﻿using System;
using System.Collections;
using FX.CC.Andon.Entity.BasicDataManage;
using FX.CC.Andon.Service.BasicDataManage;
using FX.CC.Andon.Utility.Json;

namespace FX.CC.Andon.Business.BasicDataManage
{
    public class ShiftBusiness
    {
        private readonly ShiftService _dal = new ShiftService();

        public string GetShiftList(ShiftQcEntity qcmodel)
        {
            var total = _dal.GetShiftCount(qcmodel);
            var list = _dal.GetShiftList(qcmodel);
            return JsonHelper.Encode(total, list);
        }

        public string GetShiftListByCombobox()
        {
            return JsonHelper.Encode(_dal.GetShiftListByCombobox());
        }

        public bool AddShift(string data)
        {
            var model = new ShiftEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.ShiftID = Guid.NewGuid();
                model.ShiftName = row["ShiftName"].ToString();
                model.RecStatus = true;

            }
            return _dal.AddShift(model);
        }

        public bool ModifyShift(string data)
        {
            var model = new ShiftEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.ShiftID = new Guid(row["ShiftID"].ToString());
                model.ShiftName = row["ShiftName"].ToString();
            }
            return _dal.ModifyShift(model);
        }

        public string GetShiftInfo(string id)
        {
            return JsonHelper.Encode(_dal.GetShiftInfo(id));
        }
    }
}
